const children = [];
const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/home/books'
    },
    {
        path: '/home',
        redirect: '/home/books'
    },
    {
        path: '/m_home',
        redirect: '/m_home/index'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login.vue')
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import('@/views/register.vue')
    },
    {
        path: '/m_login',
        name: 'M_Login',
        component: () => import('@/views/m_login.vue')
    },
    {
        path: '/m_register',
        name: 'M_Register',
        component: () => import('@/views/m_register.vue')
    },
    {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/home.vue'),
        children: [
            {
                path: '/home/books',
                name: 'books',
                component: () => import('@/views/home/books.vue')
            },
            {
                path: '/home/returnBook',
                name: 'returnBook',
                component: () => import('@/views/home/returnBook.vue')
            },
            {
                path: '/home/reservation',
                name: 'reservation',
                component: () => import('@/views/home/reservation.vue')
            },
            {
                path: '/home/history',
                name: 'history',
                component: () => import('@/views/home/history.vue')
            },
        ]
    },
    {
        path: '/m_home',
        name: 'M_Home',
        component: () => import('@/views/m_home/m_home.vue'),
        children: [
            {
                path: '/m_home/index',
                name: 'M_Index',
                component: () => import('@/views/m_home/index.vue')
            },
            {
                path: '/m_home/bookManagement',
                name: 'M_BookManager',
                component: () => import('@/views/m_home/bookManagement.vue')
            },
            {
                path: '/m_home/loanManagement',
                name: 'M_LoanManagement',
                component: () => import('@/views/m_home/loanManagement.vue')
            },
            {
                path: '/m_home/readerManagement',
                name: 'M_ReaderManagement',
                component: () => import('@/views/m_home/readerManagement.vue')
            },
            {
                path: '/m_home/fine',
                name: 'M_fine',
                component: () => import('@/views/m_home/fine.vue')
            },
        ]
    },
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    }
];

export const existsRoute = (path) => {
    for (let i = 0; i < routes.length; i++) {
        const r = routes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            for (let k = 0; k < r.children.length; k++) {
                const sr = r.children[k];
                if (sr.path == path) {
                    return true;
                }
            }
        }
    }
    return false;
};

export default routes;